﻿-- Удаление ветв и их дочерных записей
CREATE PROCEDURE [dbo].[axs_TreeView_RemoveSubtree]
	@iTableID [int] = 0,
	@CodeID [int]
WITH EXECUTE AS CALLER
AS
IF @iTableID BETWEEN 1 AND 3
BEGIN
	DECLARE @dynsql nvarchar(4000),@cTableName varchar(40)
	SET @cTableName = 
		CASE @iTableID 
		WHEN 1 THEN 'axsPost'  
		WHEN 2 THEN 'axsDep'  
		WHEN 3 THEN 'axsPlace'
		WHEN 4 THEN 'axsPRType'  END 
	SET @dynsql = 
	'DELETE FROM ' + @cTableName + char(13)+
	'WHERE hrccrt LIKE (SELECT hrccrt FROM ' + @cTableName + char(13)+
	'	WHERE CodeID = '+convert(varchar,@CodeID)+') + ''%'''
	EXEC(@dynsql) -- PRINT @dynsql
END


